var yfmbgl_app = function() {
	var path = Constants.amUrlPath;
	var ractive;
	var default_fz = 'Settlement inquiry';
	function renderView() {
		ractive = new Ractive({
			el : ".hp-container",
			template : "#main-template",
			onrender: function() {
			},
			oncomplete : function() {
				var _sc_param = {
						pageSize : Constants.page.pagesize,
						currPage : 1
				};
				initTable(_sc_param);
			}
		});

		ractive.on({
			pldc:function(){
				var _cxparam = {};
				var _param = review();
				var sj = JSON.stringify(_param);
				//var cs ="sqsjks="+_param.sqsjks+"&sqsjjs="+_param.sqsjjs+"&jssjks="+_param.jssjks+"&jssjjs="+_param.jssjjs+"&jsfzh="+_param.jsfzh+"&jsfmc="+_param.jsfmc;
				// 合并查询参数
				//var objs = $.extend(_cxparam, _param);
				//window.open(path + "qzjyjs/pldcJsxx?sj="+sj);
				openPostWindow(path + "qzjyjs/pldcJsxx",sj);
				
			},
			cxbutton : function() {
				var _cx_param = {
						pageSize : Constants.page.pagesize,
						currPage : 1
				};
				var _param = review();
				// 合并查询参数
				var objs = $.extend(_cx_param, _param);
				initTable(objs);
			}
		});
	}
	
	//用post请求打开
	function openPostWindow(url,data1){

	    var tempForm = document.createElement("form");
	    tempForm.id = "tempForm1";
	    tempForm.method = "post";
	    tempForm.action = url;
	   // tempForm.target="_blank"; //打开新页面
	    var hideInput1 = document.createElement("input");
	    hideInput1.type = "hidden";
	    hideInput1.name="sj"; //后台要接受这个参数来取值
	    hideInput1.value = data1; //后台实际取到的值
	    tempForm.appendChild(hideInput1);
	    document.body.appendChild(tempForm);
	    tempForm.submit();
	    document.body.removeChild(tempForm);
	}


	/**
	 * 获取参数
	 */
	function review() {
		var _param = {};
		if (typeof ractive != "undefined") {
			var param = ractive.get("jsxc");
			_param.sqsjks = (param.sq_begin_sj.length == 10 ? param.sq_begin_sj + "T00:00:00+08" : param.sq_begin_sj);
			_param.sqsjjs = (param.sq_end_sj.length == 10 ? param.sq_end_sj + "T23:59:59+08" : param.sq_end_sj);
			_param.jssjks = (param.js_begin_sj.length == 10 ? param.js_begin_sj + "T00:00:00+08" : param.js_begin_sj);
			_param.jssjjs = (param.js_end_sj.length == 10 ? param.js_end_sj + "T23:59:59+08" : param.js_end_sj);
			_param.jsfzh = $.trim(param.jsfzh);
			_param.jsfmc = $.trim(param.jsfmc);
			ractive.set("jsxc.jsfzh",_param.jsfzh);
			ractive.set("jsxc.jsfmc",_param.jsfmc);
			
		}
		return _param;
	}
	/**
	 * 获取列表数据
	 */
	function initTable(param) {
		
		var _title_sqbh = "Alipay order number";
		var _title_jsbh = "Alipay serial number ";
		var _title_jsfzh = "Settlement party account number";
		var _title_jsfmc = "Settlement party name";
		var _title_jsjf = "Settlement score";
		var _title_jsje = "Settlement amount";
		var _title_sqsj = "Application time"; 
		var _title_jssj = "Settlement time";
		var _title_cz = "Operate";
		
		
	
		var _table_title = [_title_sqbh,_title_jsbh,_title_jsfzh, _title_jsfmc, _title_jsjf , _title_jsje,_title_sqsj,_title_jssj,_title_cz];
		var _col_model = [
				{
					name : 'zfbddbh',
					width : 40,
					float:'left'
				},
				{
					name : 'zfblsh',
					width : 40,
					float:'left'
				},
				{
					name : 'jsfzh',
					width : 40
				},
				{
					name : 'jsfmc',
					width : 40,
					float:'left'
				},
				{
					name : 'jsjf',
					width : 80
				},
				{
					name : 'jsje',
					width : 80,
					innerhtml:function(opts){
						if(opts.jsje||opts.jsje=="0"){
							return "¥ " + opts.jsje;
						}
						return "";
						
					}
				},
				{
					name : 'sqsj',
					width : 80,
					innerhtml:function(opts){
					    if (opts.sqsj) {
			                return moment(opts.sqsj).format("YYYY-MM-DD HH:mm:ss");
			            } else {
			                return "";
			            }
					}
				},
				{
					name : 'jssj',
					width : 80,
					innerhtml:function(opts){
						 if (opts.jssj) {
				                return moment(opts.jssj).format("YYYY-MM-DD HH:mm:ss");
				            } else {
				                return "";
				            }
					}
				},
				{
					name : 'cz',
					width : 80,
					innerhtml:function(opts){
						
						//操作列
						//对于结算中状态的结算订单增加 操作‘处理成未结算’操作，执行该操作即更新结算状态为未结算。
						 if (opts.jszt=="2") {
							 return "<a href='javascript:void(0)' class='ad-gridlist-btn' onclick='yfmbgl_app.clwjs(\""
								+ opts.id
								+ "\")' title='Processed into unsettled' >Processed into unsettled</a>";
				            } else {
				                return "";
				            }
					}
				}
				];
		jQuery("#wd-table").wdGrid({
			url:path+'qzjyjs/getJsxxpagination',
			colNames : _table_title,
			colModel : _col_model,
			dataType : "GET",
			submitType : "noForm",
			postData : param,
			pager : "#wd-pager",
			rowList: Constants.page.rowList,
	        pagesize: Constants.page.pagesize,
    		headStyle: {
    			background: "#F2F2F2",
				height: 20,
				borderWidth: 1,
				borderColor: '#E1E1E1',
				borderStyle: 'solid',
				borderPosition: ['top', 'left', 'right', 'bottom']
    		}
		});
	}
	
	
	//处理结算中订单
	function clwjs(id){
		var fn_confirm =function(){
			
			$.ajax({
				url : path + "qzjyjs/updateClwjs?id="+id,
				type : "GET",
				dataType : "json",
				contentType : "application/json",
				success : function(obj) {
					//请求完成，启用按钮
					if(obj.result){
						var objs3 = {
								txt : "Processing successful!",
								callBackFun : function() {
									window.location.reload();
								}
							};
							success(objs3);
					}else{
						alert("Processing failed!");
						
					}
				}
			});
			
				
		};
		
	  	var objs1={
    			txt:"Are you sure to process this order?",
    			successCallBackFun:fn_confirm
    	};
    	confirm(objs1);
		
	}
	return {
		init : function() {
			renderView();
		},
		clwjs:function(id){
			clwjs(id);
		}
	};
}();
$(document).ready(yfmbgl_app.init);